<template>
  <div class="bute">
    <header>
      <div class="leftue">
        <p><i class="el-icon-s-fold"></i></p>
        <el-breadcrumb separator="/">
          <el-breadcrumb-item :to="{ path: '/about' }">主页</el-breadcrumb-item>
          <el-breadcrumb-item><a href="/bute">商品</a></el-breadcrumb-item>
          <el-breadcrumb-item>商品管理</el-breadcrumb-item>
        </el-breadcrumb>
      </div>
      <p>
        <i class="el-icon-search"></i>
        <i class="el-icon-full-screen"></i>
      </p>
    </header>
    <div class="byer">
      <el-breadcrumb>
        <el-breadcrumb-item :to="{ path: '/about' }">主页</el-breadcrumb-item>
        <el-breadcrumb-item><a href="/bute">商品管理</a></el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <main>
      <div class="brey">
        <div class="input_ret">
          <div>
            <span>商品分类：</span>
            <el-select v-model="value" placeholder="请选择">
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </div>
          <div class="input">
            <!-- 搜索 -->
            <p>商品搜索：</p>
            <el-input v-model="input" placeholder="请输入内容"></el-input>
            <el-button
              type="info"
              plain
              icon="el-icon-search"
              @click="kwywor"
            ></el-button>
          </div>
        </div>
        <!-- 添加 -->
        <el-button type="primary" @click="addlect()">新增产品分类</el-button>
      </div>
      <div>
        <el-table  :data="
              tableData.slice(
                (currentPage - 1) * pagesize,
                currentPage * pagesize
              )
            "
            style="width: 100%">
          <el-table-column type="expand" style="width:100%">
            <template slot-scope="props">
              <el-form label-position="left" inline class="demo-table-expand">
                <el-form-item label="商品名称">
                  <span>{{ props.row.title }}</span>
                </el-form-item>
                <el-form-item label="所属店铺">
                  <span>{{ props.row.shop }}</span>
                </el-form-item>
                <el-form-item label="商品 ID">
                  <span>{{ props.row.id }}</span>
                </el-form-item>
                <el-form-item label="店铺 ID">
                  <span>{{ props.row.shopId }}</span>
                </el-form-item>
                <el-form-item label="商品分类">
                  <span>{{ props.row.category }}</span>
                </el-form-item>
                <el-form-item label="店铺地址">
                  <span>{{ props.row.address }}</span>
                </el-form-item>
                <el-form-item label="商品描述">
                  <span>{{ props.row.word }}</span>
                </el-form-item>
              </el-form>
            </template>
          </el-table-column>
          <el-table-column label="名称" prop="title" width="180px">
          </el-table-column>
          <el-table-column label="类型" prop="word" width="150">
          </el-table-column>
          <el-table-column label="分类图标" width="100">
            <template slot-scope="scope">
              <img style="height: 50px" :src="scope.row.img" alt="" />
            </template>
          </el-table-column>
          <el-table-column label="排序" prop="price" width="70">
          </el-table-column>
          <el-table-column label="状态" prop="word" width="150">
          </el-table-column>
          <el-table-column label="操作" width="200">
            <template slot-scope="scope">
              <el-button
                @click="handleClick(scope.row)"
                type="text"
                size="small"
                >查看</el-button
              >
              <el-button
                @click.native.prevent="edit(scope.row, tableData)"
                type="text"
                size="small"
              >
                编辑
              </el-button>
              <el-button
                @click.native.prevent="edit(scope.row, tableData)"
                type="text"
                size="small"
              >
                删除
              </el-button>
            </template>
          </el-table-column>
        </el-table>
         <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="currentPage"
            :page-sizes="[5, 10, 20, 40]"
            :page-size="pagesize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="tableData.length"
          >
          </el-pagination>
      </div>
    </main>
  </div>
</template>

<script>
import axios from "axios";
export default {
  data() {
    return {
      activeName: "first",
      options: [],
      value: "",
      input: "",
      tableData: [],
      total: 2, //总页
      currentPage: 1, //初始页
      pagesize: 5, //每页数据

      dialogForm: false,
      form: {
        name: "",
        price: "",
        title: "",
        word: "",
      },
      formLabelWidth: "120px",
    };
  },
  created() {
    axios.get("http://127.0.0.1:7001/getList").then((res) => {
      this.tableData = res.data.data;
      console.log("res...", res.data.data);
    });
  },
  methods: {
    handleClick(tab, event) {
      // this.$router.push(`/chaxun${}`)
    },
    handleSizeChange: function (size) {
      this.pagesize = size;
    },
    handleCurrentChange: function (currentPage) {
      this.currentPage = currentPage;
    },
    //编辑
    edit(row) {
      this.dialogForm = true;
      Object.assign(this.form, { ...row });
    },
    editLi() {
      axios
        .put("http://127.0.0.1:7001/editList", { ...this.form })
        .then((res) => {
          this.dialogForm = false;
          this.$router.go(0);
        });
    },
    //搜索
    kwywor() {
      axios
        .get(`http://127.0.0.1:7001/getList/?keyword=${this.input}`)
        .then((res) => {
          this.tableData = res.data.data;
        });
    },
  },
};
</script>

<style scoped lang="scss">
.bute {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: #efefef;
}
header {
  width: 100%;
  height: 50px;
  display: flex;
  align-items: center;
  background: #fff;
  justify-content: space-between;
  padding: 0 20px;
  .leftue {
    display: flex;
  }
  i {
    font-size: 15px;
    padding: 0 10px;
  }
}
.byer {
  height: 40px;
  display: flex;
  align-items: center;
  background: #efefef;
  margin: 5px 0;
  span {
    padding: 10px 20px;
    background: #fff;
    margin: 0 5px;
  }
}
main {
  flex: 1;
  background: #fff;
  padding: 0 10px;
}
.input_ret {
  width: 100%;
  display: flex;
  padding: 10px 20px;
}
.input {
  display: flex;
  align-items: center;
  padding: 0 20px;
  p {
    width: 100px;
  }
}
.el-button {
  margin: 5px 0;
}

.el-pagination {
  width: 80%;
  text-align: center;
  padding: 20px;
}
span {
  padding: 0 20px;
}
.demo-table-expand {
  font-size: 0;
}
.demo-table-expand label {
  width: 90px;
  color: #99a9bf;
}
.demo-table-expand .el-form-item {
  margin-right: 0;
  margin-bottom: 0;
  width: 50%;
}

</style>